﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DPW.Business.Repository;
using DPW.Entity;

namespace DPW.Business.Model
{
    public class PoemModel
    {
        private Poem poem;

        public PoemModel()
        {
            this.poem = new Poem();
        }
        public PoemModel(Poem poem)
        {
            this.poem = poem;
        }

        public int Id
        {
            get { return poem.PoemId; }
        }

        public string Name
        {
            get { return poem.PoemName; }
            set { poem.PoemName = value; }
        }

        public string Content
        {
            get { return poem.PoemContent; }
            set { poem.PoemName = value; }
        }

        public string Summary
        {
            get { return poem.PoemSummary; }
            set { poem.PoemSummary = value; }
        }

        public string Author
        {
            get { return poem.PoemAuthor; }
        }

        public DateTime DateCreated
        {
            get
            {
                if (poem.DateCreated.HasValue)
                    return poem.DateCreated.Value;
                else
                    return DateTime.Now;
            }
        }

        public string DateCreatedDisplay
        {
            get
            {
                if (poem.DateCreated.HasValue)
                    return poem.DateCreated.Value.ToString("MMMM dd, yyyy hh:mm tt");
                else
                    return string.Empty;
            }
        }
        public string DateCreatedShortDisplay
        {
            get
            {
                if (poem.DateCreated.HasValue)
                    return poem.DateCreated.Value.ToString("MMMM dd, hh:mm tt");
                else
                    return string.Empty;
            }
        }

        public int Views
        {
            get { return poem.Views; }
            set { poem.Views = value; }
        }
        public int CategoryId
        {
            get { return poem.CategoryId; }
        }
        public CategoryModel Category
        {
            get { return CategoryRepository.GetCategory(CategoryId); }
        }

        public int Update()
        {
            PoemRepository.UpdatePoem(this);
            return 1;
        }
    }
}
